package hyj.qx.websocket.controller;

import hyj.qx.websocket.service.Service.MessageBroadcaster;
import hyj.qx.websocket.service.Service.MessageRankService;
import hyj.qx.websocket.service.Service.OnlineUserService;
import hyj.qx.websocket.vo.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Set;

@RestController
@Api(tags = "Redis测试接口")
public class TestController {
    @Autowired
    private OnlineUserService onlineUserService;
    @Autowired
    private MessageRankService messageRankService;
    @Autowired
    private MessageBroadcaster messageBroadcaster;

    @PostMapping("/GetUserOnline")
    @ApiOperation("获取在线列表")
    public JsonResult<Set<String>> getOnlineUsers(@RequestParam String user1 ,@RequestParam String user2){
        onlineUserService.clearOnlineUsers();
        onlineUserService.userLogin(user1);
        onlineUserService.userLogin(user2);

        Set<String> users = onlineUserService.getOnlineUsers();
        return JsonResult.success(users);

    }
    @PostMapping("/GetPHB")
    @ApiOperation("获取消息排行榜")
    public JsonResult<Set<ZSetOperations.TypedTuple<String>>> testMessageRanking(@RequestParam String user1 ,@RequestParam String user2,@RequestParam String user3){
        messageRankService.incrementMessageCount(user1);
        messageRankService.incrementMessageCount(user2);
        messageRankService.incrementMessageCount(user3);
        Set<ZSetOperations.TypedTuple<String>> top  =  messageRankService.getTopUsers();
        return JsonResult.success(top);

    }


}
